package com.example.demo.controller;

import com.example.demo.pojo.EnterpriseUsers;
import com.example.demo.service.EnterpriseUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/enterpriseUsers")
public class EnterpriseUsersController {
    @Autowired
    private EnterpriseUsersService enterpriseUsersService;

    @PostMapping("/updateEnterpriseUsers")
    public Object updateEnterpriseUsers(@RequestBody EnterpriseUsers enterpriseUsers) {
        HashMap<String, Object> map = new HashMap();
        int i = enterpriseUsersService.updateEnterpriseUsers(enterpriseUsers);
        if (i > 0) {
            map.put("code", 200);
            map.put("msg", "修改成功");
        } else {
            map.put("code", 300);
            map.put("msg", "修改失败");
        }

        return map;

    }


    //企业用户登录
    @PostMapping("/enterpriseUsersLogin")
    public Object enterpriseUsersLogin(@RequestBody EnterpriseUsers enterpriseUsers) {
        HashMap<String, Object> map = new HashMap();
        EnterpriseUsers user = enterpriseUsersService.loginInfo(enterpriseUsers);
        if (user != null) {
            map.put("code", 200);
            map.put("msg", "登录成功");
            map.put("data", user);
        } else {
            map.put("code", 300);
            map.put("msg", "账号或密码错误");
        }
        return map;
    }

    //企业用户注册
    @PostMapping("/enterpriseUsersRegister")
    public Object enterpriseUsersRegister(@RequestBody EnterpriseUsers enterpriseUsers) {
        HashMap<String, Object> map = new HashMap();
        try {
            int i = enterpriseUsersService.addEnterpriseUsers(enterpriseUsers);
            if (i > 0) {
                map.put("code", 200);
                map.put("msg", "注册成功");
            } else {
                map.put("code", 300);
                map.put("msg", "注册失败");
            }
        } catch (Exception exception) {
            map.put("code", 400);
            map.put("msg", "注册失败hjcd");
        } finally {
            return map;
        }
    }
}
